package com.sjsq.service.impl;

import com.sjsq.dao.impl.UserDao;
import com.sjsq.dao.impl.UserDaoImpl;
import com.sjsq.po.User;

import java.util.ArrayList;
import java.util.List;

/**
 * @author DHS
 * @date 2020/12/02 09:56
 */
public class UserServiceImpl implements UserService {

    // 定义dao对象
    private UserDao dao = (UserDao) new UserDaoImpl();

    /**
     * 查询用户信息
     * @param user
     * @return
     */
    @Override
    public List<User> selectUser(User user) {

        StringBuffer sql = new StringBuffer("select * from user where 1 = 1 ");
        List<Object> list = new ArrayList<Object>();
        if(user != null){

            // 按照姓名查询
            if(user.getName() != null && !user.getName().equals("")){
                sql.append(" and name = ?");
                list.add(user.getName());
            }
            // 按照email查询
            if(user.getEmail() != null && !user.getEmail().equals("")){
                sql.append(" and email = ?");
                list.add(user.getEmail());
            }
        }
        // 交给dao层处理逻辑
        return dao.selectUser(sql.toString(),list.toArray());
    }
}